home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3014 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  937 b 

  1. Path: netnews1.apci.com!usenet
  2. From: wardmw@apci.com (Martin Ward)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Keyboard input: C's equivalent to BASIC's Inkey$
  5. Date: Thu, 25 Jan 1996 13:50:09 GMT
  6. Organization: Air Products Europe
  7. Message-ID: <4e822q$fls@netnews1.apci.com>
  8. References: <Pine.SUN.3.91.960111212844.17033A@suntan>
  9. Reply-To: wardmw@apci.com
  10. NNTP-Posting-Host: p1862.apci.com
  11. X-Newsreader: Forte Free Agent 1.0.82
  12.  
  13. The following will work for DOS:
  14.  
  15. >DO
  16. >  DO WHILE k$ = ""  'As long as there is no key, keep waiting
  17. >    k$=Inkey$
  18. >    ' Additional statements to increment a counter, update and display a
  19. >    ' clock with running seconds, etc, can go here.
  20. >  LOOP
  21. >  PRINT k$;         'Print the key that was just gotten
  22. >  k$=""
  23. >LOOP
  24.  
  25. while (TRUE)
  26. {
  27.     while (! kbhit() )    /* Returns FALSE if no key pressed */
  28.     {
  29.         /* Do something else here */
  30.     }
  31.     k = getch();    /* Get the key that was pressed */
  32.     printf("%c\n", k);
  33. }
  34.  
  35. HTH
  36.  
  37. |\/|
  38.  
  39.